﻿using System;
using Contracts.Entities;
using System.Collections.Generic;
using Contracts.Library;

namespace Definition.WebImport
{
    internal static class ConvertTmdbSearchMovie
    {
        internal static MovieItem Convert(TmdbMovieSearchItem searchMovie, string name, byte[] cover)
        {
            var movieItem = new MovieItem();
            movieItem.Name = name;
            movieItem.TmdbName = searchMovie.Name;
            movieItem.TmdbId = searchMovie.Id.ToString();
            movieItem.TmdbUrl = searchMovie.Url;
            movieItem.Cover = cover;

            //Release 
            if (!String.IsNullOrEmpty(searchMovie.Released))
            {
                var year = movieItem.ReleaseYear;

                if (Int16.TryParse(searchMovie.Released.Substring(0, 4), out year))
                    movieItem.ReleaseYear = year;
            }

            return movieItem;
        }
    }
}
